Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.
题目大意:判断一个数字时候是回文,不允许有额外的空间
题目难度:Easy
/**
* Created by gzdaijie on 16/5/4
* 与第七题是相同的,判断翻转后的数字是否等于原来的数字即可
* 担心翻转后溢出,故使用了long
*/
public class Solution {
public boolean isPalindrome(int x) {
if (x < 0) return false;
long y = x;
long result = 0;
while (x > 0) {
result = result * 10 + x % 10;
x /= 10;
}
return result == y;
}
}